package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.BjtjQsList;
import com.approval.approvalapp.center.acitivty.BjtjXqActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class BjtjQsAdapter extends RecyclerView.Adapter<BjtjQsAdapter.Holder> {

    List<BjtjQsList> bjtjQsLists;
    Context context;

    public void setBjtjQsLists(List<BjtjQsList> bjtjQsLists) {
        this.bjtjQsLists = bjtjQsLists;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_qs, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tvName1.setText(bjtjQsLists.get(position).getRegion_name());
        holder.tvName2.setText(bjtjQsLists.get(position).getDaynums()+ "");
        holder.tvName3.setText(bjtjQsLists.get(position).getMonthnums()+"");
        holder.tvName4.setText(bjtjQsLists.get(position).getThreenums() + "");
        holder.tvName5.setText(bjtjQsLists.get(position).getAllnums() + "");

        holder.xqLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("id" , bjtjQsLists.get(position).getRegion_code());
                intent.setClass(context,BjtjXqActivity.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (bjtjQsLists == null) {
            return 0;
        } else {
            return bjtjQsLists.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_name1)
        TextView tvName1;
        @Bind(R.id.tv_name2)
        TextView tvName2;
        @Bind(R.id.tv_name3)
        TextView tvName3;
        @Bind(R.id.tv_name4)
        TextView tvName4;
        @Bind(R.id.tv_name5)
        TextView tvName5;
        @Bind(R.id.xq_ll)
        LinearLayout xqLl;
        @Bind(R.id.root)
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
